2020-2021 Sunseeker Telemetry and Lighting System
comp_d_ex5_outputToggleHysteresis.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR57xx Demo - COMPD Hysteresis, CDOUT Toggle in LPM4; High speed mode
34 //
35 // Description: Use Compd and shared reference to determine if input 'Vcompare'
36 // is high of low. Shared reference is configured to generate hysteresis.
37 // When Vcompare exceeds Vcc*3/4 CDOUT goes high and when Vcompare is less
38 // than Vcc*1/4 then CDOUT goes low.
39 // P3.5/CDOUT is connected internally to an LED; it will toggle accordingly.
40 //
41 // MSP430FR5739
42 // ------------------
43 // /|\| |
44 // | | |
45 // --|RST P1.2/CD2 |<--Vcompare
46 // | |
47 // | P3.5/CDOUT|----> 'high'(Vcompare>Vcc*3/4); 'low'(Vcompare<Vcc*1/4)
48 // | | |
49 // | | | LED 'ON'(Vcompare>Vcc*3/4); 'OFF'(Vcompare<Vcc*1/4)
50 // | |
51 //
52 //******************************************************************************
53 #include "driverlib.h"
54 
55 void main(void)
56 {
57  //Stop WDT
58  WDT_A_hold(WDT_A_BASE);
59 
60  //Set P3.5 as Ternary Module Function Output.
61  /*
62  * Select Port 3
63  * Set Pin 5 to output Ternary Module Function, (CBOUT).
64  */
65  GPIO_setAsPeripheralModuleFunctionOutputPin(
66  GPIO_PORT_P3,
67  GPIO_PIN5,
68  GPIO_TERNARY_MODULE_FUNCTION
69  );
70 
71  //Initialize the Comparator D module
72  /* Base Address of Comparator D,
73  * Pin CD2 to Positive(+) Terminal,
74  * Reference Voltage to Negative(-) Terminal,
75  * Normal Power Mode,
76  * Output Filter On with minimal delay,
77  * Non-Inverted Output Polarity
78  */
79  Comp_D_initParam param = {0};
80  param.positiveTerminalInput = COMP_D_INPUT2;
81  param.negativeTerminalInput = COMP_D_VREF;
82  param.outputFilterEnableAndDelayLevel = COMP_D_FILTEROUTPUT_OFF;
83  param.invertedOutputPolarity = COMP_D_NORMALOUTPUTPOLARITY;
84  Comp_D_init(COMP_D_BASE, &param);
85 
86  //Set the reference voltage that is being supplied to the (-) terminal
87  /* Base Address of Comparator D,
88  * Reference Voltage of Vcc V,
89  * Lower Limit of Vcc*(8/32) = Vcc*1/4,
90  * Upper Limit of Vcc*(24/32) = Vcc*3/4,
91  * Static Mode Accuracy
92  */
93  Comp_D_setReferenceVoltage(COMP_D_BASE,
94  COMP_D_REFERENCE_AMPLIFIER_DISABLED,
95  8,
96  24
97  );
98 
99  //Disable Input Buffer on P1.2/CD2
100  /* Base Address of Comparator D,
101  * Input Buffer port
102  * Selecting the CDx input pin to the comparator
103  * multiplexer with the CDx bits automatically
104  * disables output driver and input buffer for
105  * that pin, regardless of the state of the
106  * associated CDPD.x bit
107  */
108  Comp_D_disableInputBuffer(COMP_D_BASE,
109  COMP_D_INPUT2);
110 
111  //Allow power to Comparator module
112  Comp_D_enable(COMP_D_BASE);
113 
114  __delay_cycles(400); // delay for the reference to settle
115 
116  __bis_SR_register(LPM4_bits); // Enter LPM4
117  __no_operation(); // For debug
118 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)